//
//  SecondsToCountdownStringValueTransformer.m
//  EVE Mac Suite
//
//  Created by Vadim Lozko on 4/15/09.
//  Copyright 2009  __Vadim__. All rights reserved.
//

#import "SecondsToCountdownStringValueTransformer.h"
#import "EMSSkillTrainingInfo.h"

@implementation SecondsToCountdownStringValueTransformer

+ (Class)transformedValueClass
{
	return [NSString class];
}

+ (BOOL)allowsReverseTransformation
{
    return NO;
}

- (id)transformedValue:(id)value
{
	if(value == nil) return @"";
	double seconds = [(NSNumber*)value doubleValue];
	HumanNotationTime time = [EMSSkillTrainingInfo humanNotationTimeFromTimeInterval:seconds];
	NSString* days = (time.days > 0) ? [NSString stringWithFormat:@"%iD", time.days] : @"";
	NSString* hours = (time.days == 0 && time.hours == 0) ? @"" : [NSString stringWithFormat:@"%iH", time.hours];
	NSString* minutes = (time.days == 0 && time.hours == 0 && time.minutes == 0) ? @"" : [NSString stringWithFormat:@"%iM", time.minutes];
	return [NSString stringWithFormat:@"%@ %@ %@ %iS", days, hours, minutes, time.seconds];
}

@end
